home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UGroupTreeCmds.cp < prev    next >
Encoding:
Text File  |  1994-02-20  |  11.2 KB  |  449 lines  |  [TEXT/MPS ]

  1. // Copyright Â© 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UGroupTreeCmds.cp
  3.  
  4. #include "UGroupTreeCmds.h"
  5. #include "UGroupTreeView.h"
  6. #include "UNewsAppl.h"
  7. #include "UGroupTreeDoc.h"
  8. #include "UGroupTree.h"
  9. #include "UGroupList.h"
  10. #include "UProgress.h"
  11.  
  12. #include <RsrcGlobals.h>
  13.  
  14. #pragma segment MyGroupList
  15.  
  16. #define qDebugTreeKey qDebug & 0
  17. #define qDebugTreeKeyVerbose qDebugTreeKey
  18.  
  19. //========================================================================
  20. TExpandGroupTracker::TExpandGroupTracker()
  21. {
  22. }
  23.  
  24.  
  25. pascal void TExpandGroupTracker::Initialize()
  26. {
  27.     inherited::Initialize();
  28.     fGroupTreeView = nil;
  29.     fWayDown = false;
  30.     fLastHighlighted = false;
  31. }
  32.  
  33. pascal void TExpandGroupTracker::IExpandGroupTracker(
  34.                                                 TGroupTreeView *groupTreeView,
  35.                                                 const VPoint &itsMouse,
  36.                                                 GridCell cell,
  37.                                                 Boolean isExpanded,
  38.                                                 Boolean wayDown,
  39.                                                 const Rect &cellRect)
  40. {
  41.     this->ITracker(cExpandGroup, nil, kCantUndo, kDoesNotCauseChange, NULL, 
  42.                     groupTreeView, nil, itsMouse);
  43.     fGroupTreeView = groupTreeView;
  44.     fCell = cell;
  45.     fWasExpanded = isExpanded;
  46.     fCellRect = cellRect;
  47.     fWayDown = wayDown;
  48.     fLastHighlighted = false;
  49. }
  50.  
  51. pascal void TExpandGroupTracker::DoIt()
  52. {
  53.     fGroupTreeView->ExpandCompactCell(fCell, !fWasExpanded, fWayDown);
  54. }
  55.  
  56. pascal void TExpandGroupTracker::TrackFeedback(TrackPhase /* aTrackPhase */,
  57.                                         const VPoint& /* anchorPoint */,
  58.                                         const VPoint& /* previousPoint */,
  59.                                         const VPoint& /* nextPoint */,
  60.                                         Boolean /* mouseDidMove */,
  61.                                         Boolean /* turnItOn */)
  62. {
  63. }
  64.  
  65. pascal TTracker *TExpandGroupTracker::TrackMouse(TrackPhase aTrackPhase,
  66.                                              VPoint& /* anchorPoint */,
  67.                                              VPoint& /* previousPoint */,
  68.                                              VPoint &nextPoint,
  69.                                              Boolean mouseDidMove) // override 
  70. {
  71.     if (!mouseDidMove && aTrackPhase != trackPress)
  72.         return this;
  73.     fGroupTreeView->Focus();
  74.  
  75.     Point mouse(fGroupTreeView->ViewToQDPt(nextPoint));
  76.     Boolean inside = fCellRect.Contains(mouse);
  77.     if (mouse.h < fCellRect.left || mouse.h > fCellRect.left + 14)
  78.         inside = false;
  79.     if (inside == fLastHighlighted && aTrackPhase != trackRelease)
  80.         return this; // no change
  81.     fLastHighlighted = inside;
  82.  
  83.     fGroupTreeView->DrawTrackedTriangle(fCell, fWasExpanded, false, inside);
  84.  
  85.     if (aTrackPhase != trackRelease)
  86.         return this;
  87.  
  88.     if (!inside)
  89.         return nil; // outside, don't do anything
  90.     fGroupTreeView->DrawTrackedTriangle(fCell, false, true, true);
  91.     long dl;
  92.     Delay(2, dl); // from hacking Finderâ„¢
  93.     fGroupTreeView->DrawTrackedTriangle(fCell, !fWasExpanded, false, true);
  94.     return this;
  95. }
  96.  
  97. //========================================================================
  98. TSubscribeGroupTracker::TSubscribeGroupTracker()
  99. {
  100. }
  101.  
  102.  
  103. pascal void TSubscribeGroupTracker::Initialize()
  104. {
  105.     inherited::Initialize();
  106.     fGroupTreeView = nil;
  107. }
  108.  
  109. pascal void TSubscribeGroupTracker::ISubscribeGroupTracker(
  110.                                                 TGroupTreeView *groupTreeView,
  111.                                                 const VPoint &localMouse,
  112.                                                 Boolean makingCopy)
  113. {
  114.  
  115. #if qDebug
  116.     if (!IsObject(groupTreeView))
  117.         ProgramBreak("groupTreeView is not object");
  118. #endif
  119.     groupTreeView->Focus();
  120.     CPoint globalMouse(localMouse.ToPoint());
  121.     LocalToGlobal(globalMouse);
  122.  
  123. #if qDebugGroupDrag
  124.     fprintf(stderr, "ISubscribeGroupTracker, localMouse = %s,", (char*)localMouse);
  125.     fprintf(stderr, "globalMouse = %s\n", (char*)globalMouse);
  126. #endif
  127.     IGroupTracker(cGroupListChange, globalMouse, makingCopy);
  128.     fGroupTreeView = groupTreeView;
  129.     
  130.     fMouseOffsetInGrayPict = localMouse.ToPoint();
  131. }
  132.  
  133. pascal void TSubscribeGroupTracker::Free()
  134. {
  135.     inherited::Free();
  136. }
  137.  
  138.  
  139. void TSubscribeGroupTracker::MakeGrayPict()
  140. {
  141.     fGroupTreeView->Focus();    
  142.     ClipRect(CRect(0, 0, 1000, 1000));
  143.     fGrayPictH = OpenPicture(CRect(0, 0, 1000, 1000));
  144.     PenNormal();
  145.     PenPat(&qd.gray);
  146.     PenMode(patXor);
  147.     if (!fGroupTreeView->IsAnyCellSelected())
  148.     {
  149. #if qDebugGroupDrag
  150.         fprintf(stderr, "No cell selected\n");
  151. #endif
  152.         ClosePicture();
  153.         return;
  154.     }
  155.  
  156.     fHasPrevCell = false;
  157.     
  158.     ArrayIndex firstLine = fGroupTreeView->FirstSelectedCell().v;
  159.     ArrayIndex lastLine = fGroupTreeView->LastSelectedCell().v;
  160.     CPoint offset;
  161.     Boolean gotOffset = false;
  162. #if qDebugGroupDrag
  163.     fprintf(stderr, "firstLine = %ld, lastLine = %ld\n", firstLine, lastLine);
  164. #endif
  165.     ArrayIndex line = firstLine;
  166.     while (line <= lastLine)
  167.     {
  168.         if (!fGroupTreeView->IsCellSelected(GridCell(1, short(line))))
  169.         {
  170. #if qDebugGroupDrag
  171.             fprintf(stderr, "Skips line %ld as it's not selected\n", line);
  172. #endif
  173.             line++;
  174.             continue;
  175.         }
  176.         ArrayIndex noSubLines = 1;
  177.         Boolean atFolder = true;
  178.         while (noSubLines)
  179.         {
  180.             CStr255 text;
  181.             long level, noVisibleSubLines;
  182.             Boolean isFolder;
  183.             CRect triangleRect, iconRect, textRect;
  184.             
  185.             fGroupTreeView->GetCellInformation(GridCell(1, short(line)), level, noVisibleSubLines, isFolder, triangleRect, iconRect, textRect, text);
  186.             iconRect.Inset(CPoint(1, 1));
  187.             textRect.Inset(CPoint(0, 1));
  188.             
  189.             if (!gotOffset)
  190.             {
  191.                 offset = CPoint(40, 40) - iconRect[topLeft];
  192.                 gotOffset = true;
  193.                 fMouseOffsetInGrayPict += offset;
  194.             }
  195.             iconRect += offset;
  196.             textRect += offset;
  197.             DrawGroupIcon(line, level, textRect, iconRect);
  198.             noSubLines -= 1;
  199.             if (atFolder)
  200.             {
  201.                 noSubLines += noVisibleSubLines;
  202.                 atFolder = false;
  203.             }
  204.             line++;
  205.         }
  206.     }        
  207.     if (fHasPrevCell)
  208.         FrameRect(CRect(fPrevIconRect)); // flush it
  209.     ClosePicture();
  210. }
  211.  
  212. void TSubscribeGroupTracker::DrawGroupIcon(ArrayIndex line, long level, CRect textRect, CRect iconRect)
  213. {
  214.     if (fHasPrevCell)
  215.     {
  216.         if (fPrevIndex == line - 1 && fPrevLevel == level)
  217.         {
  218.             fPrevIconRect.bottom = iconRect.bottom;
  219.             fPrevIndex++;
  220.         }
  221.         else
  222.         {
  223.             FrameRect(CRect(fPrevIconRect)); // flush it
  224.             fHasPrevCell = false;
  225.         }
  226.     }
  227.     if (!fHasPrevCell)
  228.     {
  229.         fPrevIconRect = iconRect;
  230.         fHasPrevCell = true;
  231.         fPrevLevel = level;
  232.         fPrevIndex = line;
  233.     }
  234.     FrameRect(textRect);
  235. }
  236.  
  237. void TSubscribeGroupTracker::CreateListOfDraggedGroups()
  238. {
  239.     DoFocus();
  240.     FailInfo fi;
  241.     if (fi.Try())
  242.     {
  243.         TGroupList *gl = new TGroupList();
  244.         gl->IGroupList(nil);
  245.         fDraggedGroups = gl;
  246.         
  247.         if (fGroupTreeView->IsAnyCellSelected())
  248.         {
  249.             ArrayIndex firstLine = fGroupTreeView->FirstSelectedCell().v;
  250.             ArrayIndex lastLine = fGroupTreeView->LastSelectedCell().v;
  251.             ArrayIndex line = firstLine;
  252.             TGroupTree *tree = gNewsAppl->GetGroupTreeDoc()->GetGroupTree();
  253.             while (line <= lastLine)
  254.             {
  255.                 if (!fGroupTreeView->IsCellSelected(GridCell(1, short(line))))
  256.                 {
  257.                     line++;
  258.                     continue;
  259.                 }
  260.                 CStr255 text;
  261.                 long level, noVisibleSubLines;
  262.                 Boolean isFolder;
  263.                 CRect triangleRect, iconRect, textRect;
  264.                 
  265.                 fGroupTreeView->GetCellInformation(GridCell(1, short(line)), level, noVisibleSubLines, isFolder, triangleRect, iconRect, textRect, text);
  266.  
  267.                 ArrayIndex treeIndex = tree->FindSubGroupIndexFromLine(fGroupTreeView->fExpandData, fGroupTreeView->fWindowFolderIndex, line);
  268.                 CRealGroupIterator iter(tree, treeIndex);
  269.                 for (ArrayIndex index = iter.FirstGroup(); iter.More(); index = iter.NextGroup())
  270.                 {
  271.                     if (index == kEmptyIndex)
  272.                         continue;
  273.                     CStr255 name;
  274.                     tree->GetDotNameFromNodeIndex(index, name);
  275.                     fDraggedGroups->InsertGroupBefore(fDraggedGroups->fSize + 1, name);
  276.                 }
  277.                 line += noVisibleSubLines;
  278.                 line++;
  279.             }
  280.         }
  281.         fi.Success();
  282.     }
  283.     else // fail
  284.     {
  285.         fi.ReSignal();
  286.     }
  287. }
  288.  
  289.  
  290. //========================================================================
  291. TTreeTypeName::TTreeTypeName()
  292. {
  293. }
  294.  
  295.  
  296. pascal void TTreeTypeName::Initialize()
  297. {
  298.     inherited::Initialize();
  299.     fExpandData = nil;
  300.     fWindowFolderIndex = 0;
  301.     fGroupTree = nil;
  302.     fGroupTreeView = nil;
  303. }
  304.  
  305. void TTreeTypeName::ITreeTypeName(TGroupTreeView *gtv, TLongintList *expandData, ArrayIndex windowFolderIndex, TToolboxEvent *event)
  306. {
  307.     inherited::IGroupViewTypeNameCommand(gtv, event);
  308.     fGroupTreeView = gtv;
  309.     fGroupTree = fGroupTreeView->GetGroupTree();
  310.     fExpandData = expandData;
  311.     fWindowFolderIndex = windowFolderIndex;
  312. #if qDebug
  313.     if (!IsObject(fExpandData))
  314.         ProgramBreak("fExpandData is not object");
  315.     if (fWindowFolderIndex < 1 || fWindowFolderIndex > fGroupTree->GetSize())
  316.         ProgramBreak("Invalid fWindowFolderIndex");
  317.     if (!IsObject(fGroupTreeView))
  318.         ProgramBreak("fGroupTreeView is not object");
  319.     if (!IsObject(fGroupTree))
  320.         ProgramBreak("fGroupTree is not object");
  321. #endif
  322. }
  323.  
  324. pascal void TTreeTypeName::Free()
  325. {
  326.     inherited::Free();
  327. }
  328.  
  329. void TTreeTypeName::GetLineText(ArrayIndex line, CStr255 &text)
  330. {
  331.     ArrayIndex index = fGroupTree->FindSubGroupIndexFromLine(fExpandData, fWindowFolderIndex, line);
  332.     long level;
  333.     Boolean isFolder;
  334.     fGroupTree->GetDrawInfo(index, level, text, isFolder);
  335. #if qDebugTreeKeyVerbose & 0
  336.     fprintf(stderr, "TTreeKeyCommand: line = %ld, index = %ld, text = '%s', level = %ld, isFolder = %hd\n",
  337.         line, index, (char*)text, level, isFolder);
  338. #endif
  339. }
  340.  
  341. void TTreeTypeName::SetUp()
  342. {
  343.     fLastTick = fGroupTreeView->fLastTypeKeyTick;
  344.     fTypeChars = fGroupTreeView->fKeyTypeChars;
  345.     inherited::SetUp();
  346. }
  347.  
  348. void TTreeTypeName::SetDown()
  349. {
  350.     inherited::SetDown();
  351.     fGroupTreeView->fLastTypeKeyTick = fLastTick;
  352.     fGroupTreeView->fKeyTypeChars = fTypeChars;
  353. }
  354.  
  355. //========================================================================
  356. TTreeTabKeyCommand::TTreeTabKeyCommand()
  357. {
  358. }
  359.  
  360.  
  361. pascal void TTreeTabKeyCommand::Initialize()
  362. {
  363.     inherited::Initialize();
  364.     fFirstLastLine = kEmptyIndex;
  365. }
  366.  
  367. void TTreeTabKeyCommand::ITreeTabKeyCommand(TGroupTreeView *gtv, TLongintList *expandData, ArrayIndex windowFolderIndex, Boolean forward)
  368. {
  369.     inherited::IGroupViewKeyCommand(gtv);
  370.     fGroupTreeView = gtv;
  371.     fGroupTree = fGroupTreeView->GetGroupTree();
  372.     fExpandData = expandData;
  373.     fWindowFolderIndex = windowFolderIndex;
  374. #if qDebug
  375.     if (!IsObject(fExpandData))
  376.         ProgramBreak("fExpandData is not object");
  377.     if (fWindowFolderIndex < 1 || fWindowFolderIndex > fGroupTree->GetSize())
  378.         ProgramBreak("Invalid fWindowFolderIndex");
  379.     if (!IsObject(fGroupTreeView))
  380.         ProgramBreak("fGroupTreeView is not object");
  381.     if (!IsObject(fGroupTree))
  382.         ProgramBreak("fGroupTree is not object");
  383. #endif
  384.     fForward = forward;
  385. }
  386.  
  387. pascal void TTreeTabKeyCommand::Free()
  388. {
  389.     inherited::Free();
  390. }
  391.  
  392. void TTreeTabKeyCommand::GetLineText(ArrayIndex line, CStr255 &text)
  393. {
  394.     ArrayIndex index = fGroupTree->FindSubGroupIndexFromLine(fExpandData, fWindowFolderIndex, line);
  395.     long level;
  396.     Boolean isFolder;
  397.     fGroupTree->GetDrawInfo(index, level, text, isFolder);
  398. #if qDebugTreeKeyVerbose & 0
  399.     fprintf(stderr, "TTreeKeyCommand: line = %ld, index = %ld, text = '%s', level = %ld, isFolder = %hd\n",
  400.         line, index, (char*)text, level, isFolder);
  401. #endif
  402. }
  403.  
  404. //========================================================================
  405. pascal void TUpdateListOfAllGroupsCommand::Initialize()
  406. {
  407.     inherited::Initialize();
  408.     fGroupTreeDoc = nil;
  409. }
  410.  
  411. void TUpdateListOfAllGroupsCommand::IUpdateListOfAllGroupsCommand(TGroupTreeDoc *gtd, Boolean rebuild)
  412. {
  413.     inherited::ICommand(cUpdateGroupTree, nil, false, false, nil);
  414.     fGroupTreeDoc = gtd;
  415.     fRebuild = rebuild;
  416. #if qDebug
  417.     if (!IsObject(fGroupTreeDoc))
  418.         ProgramBreak("fGroupTreeDoc is not object");
  419. #endif
  420. }
  421.  
  422. pascal void TUpdateListOfAllGroupsCommand::Free()
  423. {
  424.     fGroupTreeDoc = nil;
  425.     inherited::Free();
  426. }
  427.  
  428. pascal void TUpdateListOfAllGroupsCommand::DoIt()
  429. {
  430.     FailInfo fi;
  431.     if (fi.Try())
  432.     {
  433.         fGroupTreeDoc->CloseAllWindows();
  434.         gCurProgress->SetProgressType(true, false);
  435.         gCurProgress->SetTitle(kUpdGTProgressTitle);
  436.         if (fRebuild)
  437.             fGroupTreeDoc->RebuildGroupTree();
  438.         else
  439.             fGroupTreeDoc->UpdateGroupTree();
  440.         gCurProgress->WorkDone();
  441.         fi.Success();
  442.     }
  443.     else // fail
  444.     {
  445.         gCurProgress->WorkDone();
  446.         fi.ReSignal();
  447.     }
  448. }
  449.